package br.unicamp.integralization;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import br.unicamp.integralization.request.RequestControllerTask;
import br.unicamp.integralization.request.RequestTask;

public class RARequestActivity extends Activity {

	private EditText raEditText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ra_request);

		raEditText = (EditText) findViewById(R.id.ra_edit_text);
		Button integralizateButton = (Button) findViewById(R.id.integralizate_button);

		integralizateButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				InputMethodManager imm = (InputMethodManager)getSystemService(
					      Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(raEditText.getWindowToken(), 0);
					
				String ra = raEditText.getText().toString();
				new RequestControllerTask(RARequestActivity.this).execute(
						RequestControllerTask.URL_GET_DATA,
						RequestTask.METHOD_GET, "ra=" + ra);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
